﻿myApp.controller("SignCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    $scope.checkResult = {};
    //时间控件
    $scope.getSignRecord = function () {
        $http({ method: "GET", url: $restUrls["getSignRecords"], params: {} }).success(function (result) {
            if (result.success == 1) {
                $("#datepicker").datepicker({
                    inline: true,
                    showOtherMonths: true,
                    dateFormat: "yy/mm/dd",
                    defaultDate: 0,
                    beforeShowDay: function (date) {
                        var day = new Date(date);
                        var datetime = '';
                        if (day.getDate() < 10) {
                            datetime = Date.parse(day.getFullYear() + '/' + (day.getMonth() + 1) + '/' + '0' + day.getDate());
                        } else {
                            datetime = Date.parse(day.getFullYear() + '/' + (day.getMonth() + 1) + '/' + day.getDate());
                        }
                        for (var i = 0; i < result.data.length; i++) {
                            var flag = false;
                            var temp_day = result.data[i].date_added.substring(0,10).replace(/-/g, "/");
                            if (Date.parse(temp_day) == datetime) {
                                flag = true;
                                break;
                            } 
                        }

                        return [flag, 'checkin', ''];
                    },
                    onSelect: function (dateText, inst) {
                        $scope.$apply(function () {
                            console.log(dateText);
                        })
                    }
                });
            } 
        });
    }
    $scope.getSignRecord();
   
    //签到
    $scope.CheckIn = function () {
        $http({ method: "GET", url: $restUrls["checkIn"], params: {  } }).success(function (result) {
            $scope.checkResult = result;
            if (result.success == 1) {
                $scope.tipsuccess = true;
                setTimeout(function () {
                    $scope.tipsuccess = false;
                    window.location.reload();
                },1500);
            } else {

            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }
    $scope.CheckIn();

    $scope.GetTodaySignRank = function () {
        $http({ method: "GET", url: $restUrls["getTodaySignRank"], params: {  } }).success(function (result) {
            if (result.success == 1) {
                $scope.rankReuslt = result;
            } else {
            }
        }).error(function (data, status, headers, config) {
            $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
        });
    }

    $scope.GetTodaySignRank();
    
    $scope.getBackBanner  =function () {
        $http({ method: "GET", url: $restUrls["getBannerImagesById"], params: { banner_id: 10 } }).success(function (result) {
            if (result.success == 1) {
                $scope.banners = result.data;
            }
        });
    }

    $scope.getBackBanner();
}]);